package com.zygh.policeasset.service;

import cn.hutool.core.date.DateUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.mapper.AuditFlowMapper;
import com.zygh.policeasset.mapper.ConstructionChangeMapper;
import com.zygh.policeasset.mapper.UploadFileMapper;
import com.zygh.policeasset.pojo.ConstructionChange;
import com.zygh.policeasset.pojo.TableType;
import com.zygh.policeasset.pojo.UploadFile;
import com.zygh.policeasset.utils.AuditUtil;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/service/ConstructionChangeService.class */
public class ConstructionChangeService {
    @Autowired
    ConstructionChangeMapper constructionChangeMapper;
    @Autowired
    UploadFileMapper uploadFileMapper;
    @Autowired
    AuditFlowMapper auditFlowMapper;
    @Autowired
    AuditFlowService auditFlowService;

    public ConstructionChange queryById(Integer id) {
        return this.constructionChangeMapper.queryById(id);
    }

    public PageInfo queryAll(int pageNum, int pageSize, Integer userId, Integer status, Integer handWay, String unit, Integer rehabilitation) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo(this.constructionChangeMapper.queryAll(userId, status, handWay, unit, rehabilitation));
    }

    public PageInfo queryStatistical(int pageNum, int pageSize, Integer userId, Integer status, Integer handWay, String unit) {
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo(this.constructionChangeMapper.queryStatistical(userId, status, handWay, unit));
    }

    public CommonResult insert(ConstructionChange constructionChange) {
        String now = DateUtil.now();
        String flowNo = AuditUtil.getFlowNo(now);
        constructionChange.setFlowNo(flowNo);
        int count = this.constructionChangeMapper.insert(constructionChange);
        List<UploadFile> uploadFileList = constructionChange.getUploadFileList();
        for (int i = 0; i < uploadFileList.size(); i++) {
            uploadFileList.get(i).setProjectId(constructionChange.getId().intValue());
            uploadFileList.get(i).setProjectName("constructionChange");
            uploadFileList.get(i).setCreateDate(now);
            this.uploadFileMapper.add(uploadFileList.get(i));
        }
        this.auditFlowService.add(constructionChange.getUserId(), flowNo, now, TableType.CONSTRUCTIONCHANGE.getName(), TableType.CONSTRUCTIONCHANGE.getType(), null, null);
        if (count > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    public CommonResult update(ConstructionChange constructionChange) {
        if (this.constructionChangeMapper.update(constructionChange) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    public CommonResult deleteById(Integer id) {
        if (this.constructionChangeMapper.deleteById(id) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }

    public CommonResult rehabilitation(Integer id) {
        ConstructionChange constructionChange = new ConstructionChange();
        constructionChange.setId(id);
        constructionChange.setRehabilitation(1);
        constructionChange.setRehabilitationTime(DateUtil.now());
        if (this.constructionChangeMapper.update(constructionChange) > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("复建失败");
    }
}